<template>
  <div class="full-screen-container">
    <svg-icon
      :name="isFullScreen ? 'screenfull-cancle' : 'screenfull'"
      @click="onToggle"
      size="22px"
    ></svg-icon>
  </div>
</template>

<script setup>
import { onMounted, onUnmounted, ref } from 'vue'
import screenfull from 'screenfull'
const isFullScreen = ref(false)
const onToggle = () => {
  screenfull.toggle()
}

// 监听screenfull的变化
const change = () => {
  isFullScreen.value = screenfull.isFullscreen
}

// on,绑定监听
onMounted(() => {
  screenfull.on('change', change)
})

// off,取消监听
onUnmounted(() => {
  screenfull.off('change', change)
})
</script>

<style lang="scss" scoped>
.full-screen-container {
  cursor: pointer;
  @include flex-align-c();
}
</style>
